package com.ist.viewpagerhelper.activity.glide;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.ist.viewpagerhelper.ContractUtils;
import com.ist.viewpagerhelper.MainActivity;
import com.ist.viewpagerhelper.R;
import com.ist.viewpagerhelper.bean.ViewPagerBean;
import com.ist.viewpagerhelper.view.GlideViewPager;
import com.ist.viewpagerhelper.indicator.ZoomIndicator;

import java.util.ArrayList;
import java.util.List;

public class GlideScaleActivity extends AppCompatActivity {

    private static final int[] RES = {R.mipmap.guide1,R.mipmap.guide2,R.mipmap.guide3,
            R.mipmap.guide4 };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_glide_scale);
        initView();
    }

    public void initView() {

        GlideViewPager viewPager = (GlideViewPager) findViewById(R.id.splase_viewpager);
        ZoomIndicator zoomIndicator = (ZoomIndicator) findViewById(R.id.splase_bottom_layout);
        Button button = (Button) findViewById(R.id.splase_start_btn);


        // 获取view的值
        List<View> views = new ArrayList<>();
        for (int i = 0; i < RES.length; i++) {
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(RES[i]);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            views.add(imageView);
        }

        ViewPagerBean bean =  new ViewPagerBean.Builder()
                .setViewPager(viewPager)
                .setMode(ContractUtils.GLIDE_MODE)
                .setIndicator(zoomIndicator)
                .setOpenView(button)
                .setDataObjects(views)
                .setDataCount(views.size())
                .builder();

        viewPager.setViewPagerBean(bean);

/*
        // 实现导航栏效果
        new ViewPagerHelper.Builder()
                .setContext(this)
                .setViewPager(viewPager)
                .setDataViews(views)
                .setLinearLayout(linearLayout)
                .setViewPagerMode(ViewPagerHelper.GLIDE)
                .setUseDefaultCircle(true)
                .setStartView(button)
                .builder();*/

        //点击实现跳转功能
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(GlideScaleActivity.this,MainActivity.class));
                Toast.makeText(GlideScaleActivity.this, "回到首页", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }
}
